package com.aistar.servlet;

import com.aistar.Job;
import com.alibaba.fastjson.JSONObject;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by Administrator on 2019/9/12.
 */
@WebServlet(name = "Test4Servlet",urlPatterns = "/test4")
public class Test4Servlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String jobname = request.getParameter("job");
        String city = request.getParameter("city");
        float salary = Float.valueOf(request.getParameter("salary"));

        System.out.println("job:"+jobname+",city:"+city+"salary:"+salary);

        Job job = new Job(jobname,city,salary);
        String josnString = JSONObject.toJSONString(job);

        response.setContentType("text/html;charset=utf-8");
        response.getWriter().print(josnString);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request,response);
    }
}
